<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateBusinessTable extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $this->table('business', ['comment'=>'业务范围'])
            ->addColumn(Column::string('title')->setNullable()->setComment('标题'))
            ->addColumn(Column::integer('cate_id')->setNullable()->setComment('分类id'))
            ->addColumn(Column::json('tags')->setNullable()->setComment('标签'))
            ->addColumn(Column::integer('change_time')->setComment('更新时间')->setNullable())
            ->addColumn(Column::text('content')->setNullable()->setComment('内容'))
            ->addColumn(Column::string('auth')->setNullable()->setComment('作者'))
            ->addColumn(Column::integer('user_id')->setNullable()->setComment('创建者'))
            ->addColumn(Column::integer('page_view')->setDefault(0)->setNullable()->setComment('浏览量'))
            ->addColumn(Column::integer('init_view')->setDefault(0)->setNullable()->setComment('初始浏览量'))
            ->addColumn(Column::json('list_style')->setNullable()->setComment('列表样式，json'))
            ->addColumn(Column::tinyInteger('top')->setDefault(0)->setNullable()->setComment('置顶，0否，1是'))
            ->addColumn(Column::json('home')->setNullable()->setComment('首页展示，json数据类型'))
            ->addColumn(Column::tinyInteger('newest')->setDefault(0)->setNullable()->setComment('最新，，0否，1是'))
            ->addColumn(Column::string('cover_link')->setNullable()->setComment('封面地址'))
            ->addColumn(Column::json('media')->setNullable()->setComment('媒体文件'))
            # 附加属性
            ->addColumn(Column::json('attachment')->setNullable()->setComment('附件地址'))
            ->addColumn(Column::integer('sort')->setDefault(0)->setNullable()->setComment('排序'))

            ->addColumn(Column::integer('publish')->setDefault(0)->setNullable()->setComment('0 待发布，1 已发布， 2 已下架'))
            #
            ->addColumn(Column::integer('create_time')->setComment('创建时间'))
            ->addColumn(Column::integer('update_time')->setComment('修改时间')->setNullable())
            ->addColumn(Column::integer('delete_time')->setComment('删除时间')->setNullable())
            ->create();
    }
}
